package com.framework.middleware.zookeeper;

import org.apache.zookeeper.*;
import org.apache.zookeeper.data.ACL;

import java.util.List;

/**
 * @author chaolong.jin
 * @description
 * @date 2019/08/09 14:09
 */
public class ZookeeperTools {
    public static void main(String[] args) {
        ZkClient zkClient = new ZkClient();
        ZooKeeper zooKeeper = zkClient.getZookeeper("localhost:2181", 40000, zkClient.getConnectionWatcher());
        System.out.println("zookeeper connectioned");
        ZooKeeper.States states = zooKeeper.getState();

        try {
//            String result = zooKeeper.create("/temp", "temp data".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL);
//            System.out.println(result);
            List<String> path = zooKeeper.getChildren("/", false);
//            List<ACL> path1Acl=  zooKeeper.getACL("/path1",null);

           List<String> customers= zooKeeper.getChildren("/consumers",false);
            byte[] data = zooKeeper.getData("/", true, null);

            List<ACL> aclList= zooKeeper.getACL("/",null);
            System.out.println(new String(data));
//            String result = zooKeeper.create("/path1", "path1 data".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
//            System.out.println(result);

        } catch (KeeperException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        states = null;
    }
}
